package com.csr.csrcheck.controller;

import com.csr.csrcheck.controller.ex.CompanyException;
import com.csr.csrcheck.pojo.Product_type;
import com.csr.csrcheck.service.ProductService;
import com.csr.csrcheck.util.JsonResult;
import com.csr.csrcheck.util.PageResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping({"product"})
public class ProductController extends BaseController {
    private static final Logger log = LoggerFactory.getLogger(com.csr.csrcheck.controller.ProductController.class);

    @Resource
    private ProductService productService;

    @RequestMapping({"productpage"})
    public JsonResult<Object> productpage(@RequestParam(defaultValue = "1") int pageNum, @RequestParam(defaultValue = "5") int pageSize, String product_name) {
        PageResult pageResult = this.productService.listpage(pageNum, pageSize, product_name);
        if (pageResult == null)
            throw new CompanyException("");
        return new JsonResult(Integer.valueOf(0), "json", pageResult);
    }

    public String selectproduct_type(Model model) {
        List<Product_type> list = this.productService.selectProduct_type();
        return "/";
    }
}
